/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.dinner.web.recharge;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.dinner.entity.recharge.ResRechargeHis;
import com.thinkgem.jeesite.modules.dinner.service.recharge.ResRechargeHisService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 充值记录Controller
 * @author dai
 * @version 2018-11-18
 */
@Controller
@RequestMapping(value = "${adminPath}/dinner/recharge/resRechargeHis")
public class ResRechargeHisController extends BaseController {

	@Autowired
	private ResRechargeHisService resRechargeHisService;
	
	@ModelAttribute
	public ResRechargeHis get(@RequestParam(required=false) String id) {
		ResRechargeHis entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = resRechargeHisService.get(id);
		}
		if (entity == null){
			entity = new ResRechargeHis();
		}
		return entity;
	}
	
	@RequiresPermissions("dinner:recharge:resRechargeHis:view")
	@RequestMapping(value = {"list", ""})
	public String list(ResRechargeHis resRechargeHis, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ResRechargeHis> page = resRechargeHisService.findPage(new Page<ResRechargeHis>(request, response), resRechargeHis); 
		model.addAttribute("page", page);
		return "modules/dinner/recharge/resRechargeHisList";
	}

	@RequiresPermissions("dinner:recharge:resRechargeHis:view")
	@RequestMapping(value = "form")
	public String form(ResRechargeHis resRechargeHis, Model model) {
		model.addAttribute("resRechargeHis", resRechargeHis);
		return "modules/dinner/recharge/resRechargeHisForm";
	}

	@RequiresPermissions("dinner:recharge:resRechargeHis:edit")
	@RequestMapping(value = "save")
	public String save(ResRechargeHis resRechargeHis, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, resRechargeHis)){
			return form(resRechargeHis, model);
		}
		resRechargeHisService.save(resRechargeHis);
		addMessage(redirectAttributes, "保存充值记录成功");
		return "redirect:"+Global.getAdminPath()+"/dinner/recharge/resRechargeHis/?repage";
	}
	
	@RequiresPermissions("dinner:recharge:resRechargeHis:edit")
	@RequestMapping(value = "delete")
	public String delete(ResRechargeHis resRechargeHis, RedirectAttributes redirectAttributes) {
		resRechargeHisService.delete(resRechargeHis);
		addMessage(redirectAttributes, "删除充值记录成功");
		return "redirect:"+Global.getAdminPath()+"/dinner/recharge/resRechargeHis/?repage";
	}
}